import React, { Component } from 'react'

class Demo extends Component {
  state = {}

  static getDerivedStateFromProps(props, state){
    console.log('Demo---getDerivedStateFromProps:', props)
    return null
  }

  shouldComponentUpdate(nexProps, nextState){
    console.log('Demo---shouldComponentUpdate')
    return true
  }

  render() {
    console.log('Demo---render')
    return <h1>Demo组件{this.props.msg}</h1>
  }

  getSnapshotBeforeUpdate(props, state) {
    console.log('Demo---getSnapshotBeforeUpdate')
    return [props, state]
  }

  componentDidUpdate(props, state, snapshot){
    console.log('Demo---componentDidUpdate来自 getSnapshotBeforeUpdate的值：', snapshot)
  }
}

export default class App extends Component {
  state = {
    msg: '🐂'
  }
  handleClick = ()=> {
    this.setState({
      msg: '🐖'
    })
  }
  render() {
    return (
      <div>
        <Demo msg={this.state.msg}></Demo>
        <button onClick={this.handleClick}>更新</button>
      </div>
    )
  }
}
